package cn.itcast.utils;

import java.sql.Date;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.locale.converters.DateLocaleConverter;

public class WebUtils {
	public static <T> T copeToBean(HttpServletRequest request, Class<T> clazz) {
		try {
			ConvertUtils.register(new DateLocaleConverter(), Date.class);

			Object t = clazz.newInstance();

			BeanUtils.populate(t, request.getParameterMap());

			return (T) t;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}